package com.senriot.quickup.web.rest

import com.querydsl.core.types.Predicate
import com.senriot.cloud.common.AbstractController
import com.senriot.cloud.common.annotation.EntityName
import com.senriot.quickup.domain.Order
import com.senriot.quickup.service.OrderService
import com.senriot.quickup.service.dto.OrderDTO
import com.senriot.quickup.service.dto.OrderStatistics
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.domain.Sort
import org.springframework.data.querydsl.binding.QuerydslPredicate
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.servlet.ModelAndView

@RestController
@RequestMapping("/api/orders")
@EntityName("order")
@Api(tags = ["订单"])
class OrderResource : AbstractController<Order, Long, OrderDTO, OrderService>()
{
    override fun loadAll(sort: Sort, @QuerydslPredicate(root = Order::class) predicate: Predicate?): List<OrderDTO>
    {
        return super.loadAll(sort, predicate)
    }

    override fun loadPage(page: Pageable, @QuerydslPredicate(root = Order::class) predicate: Predicate?): Page<OrderDTO>
    {
        return super.loadPage(page, predicate)
    }

    override fun count(@QuerydslPredicate(root = Order::class) predicate: Predicate?): ResponseEntity<Long>
    {
        return super.count(predicate)
    }

    override fun exportXls(predicate: Predicate?): ModelAndView
    {
        return super.exportXls(predicate)
    }

    @GetMapping("statistics")
    @ApiOperation("订单统计数据")
    fun statistics(): OrderStatistics
    {
        return service.statistics()
    }

    @GetMapping("store-ranking")
    @ApiOperation("门店销售排行")
    fun storeRanking() = service.storeRanking()

    @GetMapping("cash-out-statistics")
    @ApiOperation("提现统计")
    fun cashOutStatistics() = service.cashOutStatistics()

    @GetMapping("order-statistics")
    @ApiOperation("订单统计")
    fun orderStatistics() = service.orderStatistics()
}
